<template>
  <div class="dashboard-container">
    <!-- 顶部导航栏 -->
    <el-header class="header">
      <div class="header-left">
        <div class="logo">
          <svg viewBox="0 0 24 24" width="32" height="32">
            <path fill="#409EFF" d="M12 2L2 7l10 5 10-5-10-5zM2 17l10 5 10-5M2 12l10 5 10-5"/>
          </svg>
          <span class="title">在线教育管理后台</span>
        </div>
      </div>
      <div class="header-right">
        <el-dropdown>
          <span class="user-info">
            <el-icon><User /></el-icon>
            admin
            <el-icon class="el-icon--right"><arrow-down /></el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>个人中心</el-dropdown-item>
              <el-dropdown-item divided @click="logout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </el-header>

    <el-container class="main-container">
      <!-- 侧边栏 -->
      <el-aside class="sidebar" width="240px">
        <el-menu
          default-active="dashboard"
          class="sidebar-menu"
          background-color="#304156"
          text-color="#bfcbd9"
          active-text-color="#409EFF"
        >
          <el-menu-item index="dashboard">
            <el-icon><House /></el-icon>
            <span>系统首页</span>
          </el-menu-item>
          
          <el-sub-menu index="user">
            <template #title>
              <el-icon><User /></el-icon>
              <span>用户管理</span>
            </template>
            <el-menu-item index="student-management" @click="navigateTo('/student-management')">学生管理</el-menu-item>
            <el-menu-item index="teacher-management" @click="navigateTo('/teacher-management')">教师管理</el-menu-item>
          </el-sub-menu>

          <el-sub-menu index="course">
            <template #title>
              <el-icon><Reading /></el-icon>
              <span>课程管理</span>
            </template>
            <el-menu-item index="course-list">课程列表</el-menu-item>
            <el-menu-item index="course-add">添加课程</el-menu-item>
          </el-sub-menu>

          <el-sub-menu index="order">
            <template #title>
              <el-icon><ShoppingCart /></el-icon>
              <span>订单管理</span>
            </template>
            <el-menu-item index="order-list">订单列表</el-menu-item>
          </el-sub-menu>

          <el-sub-menu index="finance">
            <template #title>
              <el-icon><Money /></el-icon>
              <span>财务管理</span>
            </template>
            <el-menu-item index="finance-record">财务记录</el-menu-item>
          </el-sub-menu>

          <el-sub-menu index="system">
            <template #title>
              <el-icon><Setting /></el-icon>
              <span>系统管理</span>
            </template>
            <el-menu-item index="system-config">系统配置</el-menu-item>
            <el-menu-item index="system-log">系统日志</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </el-aside>

      <!-- 主内容区域 -->
      <el-main class="main-content">
        <!-- 统计卡片 -->
        <div class="stats-cards">
          <el-row :gutter="20">
            <el-col :span="6">
              <el-card class="stat-card stat-card-blue">
                <div class="stat-content">
                  <div class="stat-title">今日新增用户</div>
                  <div class="stat-number">200</div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="6">
              <el-card class="stat-card stat-card-pink">
                <div class="stat-content">
                  <div class="stat-title">今日新增课程</div>
                  <div class="stat-number">¥1634</div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="6">
              <el-card class="stat-card stat-card-purple">
                <div class="stat-content">
                  <div class="stat-title">累计学员数量</div>
                  <div class="stat-number">¥1480</div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="6">
              <el-card class="stat-card stat-card-orange">
                <div class="stat-content">
                  <div class="stat-title">累计收入</div>
                  <div class="stat-number">¥20000</div>
                </div>
              </el-card>
            </el-col>
          </el-row>
        </div>

        <!-- 数据统计图表 -->
        <div class="charts-section">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-card class="chart-card">
                <template #header>
                  <div class="card-header">
                    <span>课程总量</span>
                  </div>
                </template>
                <div class="chart-content">
                  <div class="chart-stats">
                    <div class="stat-item">
                      <div class="stat-value">100</div>
                      <div class="stat-label">已上架</div>
                    </div>
                    <div class="stat-item">
                      <div class="stat-value">400</div>
                      <div class="stat-label">已下架</div>
                    </div>
                    <div class="stat-item">
                      <div class="stat-value">50</div>
                      <div class="stat-label">已完结</div>
                    </div>
                    <div class="stat-item">
                      <div class="stat-value">500</div>
                      <div class="stat-label">全部课程</div>
                    </div>
                  </div>
                </div>
              </el-card>
            </el-col>
            <el-col :span="12">
              <el-card class="chart-card">
                <template #header>
                  <div class="card-header">
                    <span>用户总量</span>
                  </div>
                </template>
                <div class="chart-content">
                  <div class="chart-stats">
                    <div class="stat-item">
                      <div class="stat-value">100</div>
                      <div class="stat-label">今日新增</div>
                    </div>
                    <div class="stat-item">
                      <div class="stat-value">200</div>
                      <div class="stat-label">月新增</div>
                    </div>
                    <div class="stat-item">
                      <div class="stat-value">1000</div>
                      <div class="stat-label">本月总数</div>
                    </div>
                    <div class="stat-item">
                      <div class="stat-value">5000</div>
                      <div class="stat-label">用户总数</div>
                    </div>
                  </div>
                </div>
              </el-card>
            </el-col>
          </el-row>
        </div>

        <!-- 快捷操作入口 -->
        <div class="quick-actions">
          <el-card>
            <template #header>
              <div class="card-header">
                <span>管理快捷入口</span>
              </div>
            </template>
            <div class="action-grid">
              <div class="action-item" @click="handleAction('add-course')">
                <el-icon class="action-icon"><Plus /></el-icon>
                <span class="action-text">添加课程</span>
              </div>
              <div class="action-item" @click="handleAction('order-list')">
                <el-icon class="action-icon"><List /></el-icon>
                <span class="action-text">订单列表</span>
              </div>
              <div class="action-item" @click="handleAction('student-manage')">
                <el-icon class="action-icon"><UserFilled /></el-icon>
                <span class="action-text">学生管理</span>
              </div>
              <div class="action-item" @click="handleAction('data-export')">
                <el-icon class="action-icon"><Connection /></el-icon>
                <span class="action-text">数据导出</span>
              </div>
              <div class="action-item" @click="handleAction('live-manage')">
                <el-icon class="action-icon"><VideoCamera /></el-icon>
                <span class="action-text">直播管理</span>
              </div>
              <div class="action-item" @click="handleAction('finance-record')">
                <el-icon class="action-icon"><Coin /></el-icon>
                <span class="action-text">金融记录</span>
              </div>
              <div class="action-item" @click="handleAction('notice-manage')">
                <el-icon class="action-icon"><Grid /></el-icon>
                <span class="action-text">公告管理</span>
              </div>
            </div>
          </el-card>
        </div>

        <!-- 订单统计 -->
        <div class="order-stats">
          <el-card>
            <template #header>
              <div class="card-header">
                <span>订单统计</span>
                <div class="date-range">
                  <el-date-picker
                    v-model="dateRange"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    size="small"
                  />
                </div>
              </div>
            </template>
            <div class="order-content">
              <div class="order-summary">
                <span class="order-label">本月订单总数</span>
                <span class="order-value">10000</span>
              </div>
            </div>
          </el-card>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import {
  User,
  ArrowDown,
  House,
  Reading,
  ShoppingCart,
  Money,
  Setting,
  Plus,
  List,
  UserFilled,
  Connection,
  VideoCamera,
  Coin,
  Grid
} from '@element-plus/icons-vue'

const router = useRouter()
const dateRange = ref([])

const logout = () => {
  ElMessage.success('退出登录成功')
  // 这里可以添加退出登录的逻辑
}

const navigateTo = (path) => {
  router.push(path)
}

const handleAction = (action) => {
  ElMessage.info(`点击了${action}`)
  // 这里可以添加对应的路由跳转或操作逻辑
}
</script>

<style scoped>
.dashboard-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background: #fff;
  border-bottom: 1px solid #e4e7ed;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 60px;
}

.header-left .logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-left .title {
  font-size: 20px;
  font-weight: 600;
  color: #303133;
}

.header-right .user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: #606266;
}

.main-container {
  flex: 1;
  height: calc(100vh - 60px);
}

.sidebar {
  background: #304156;
}

.sidebar-menu {
  border: none;
  height: 100%;
}

.main-content {
  background: #f0f2f5;
  padding: 20px;
  overflow-y: auto;
}

.stats-cards {
  margin-bottom: 20px;
}

.stat-card {
  border: none;
  border-radius: 8px;
  overflow: hidden;
}

.stat-card-blue {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.stat-card-pink {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
}

.stat-card-purple {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  color: white;
}

.stat-card-orange {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
  color: white;
}

.stat-content {
  text-align: center;
  padding: 20px;
}

.stat-title {
  font-size: 14px;
  margin-bottom: 10px;
  opacity: 0.9;
}

.stat-number {
  font-size: 28px;
  font-weight: bold;
}

.charts-section {
  margin-bottom: 20px;
}

.chart-card {
  border-radius: 8px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
}

.chart-content {
  padding: 20px 0;
}

.chart-stats {
  display: flex;
  justify-content: space-around;
  text-align: center;
}

.stat-item {
  flex: 1;
}

.stat-value {
  font-size: 24px;
  font-weight: bold;
  color: #409EFF;
  margin-bottom: 8px;
}

.stat-label {
  font-size: 14px;
  color: #909399;
}

.quick-actions {
  margin-bottom: 20px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 20px;
  padding: 20px 0;
}

.action-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  background: #f8f9fa;
}

.action-item:hover {
  background: #e3f2fd;
  transform: translateY(-2px);
}

.action-icon {
  font-size: 32px;
  color: #409EFF;
}

.action-text {
  font-size: 14px;
  color: #606266;
}

.order-stats {
  margin-bottom: 20px;
}

.date-range {
  display: flex;
  align-items: center;
}

.order-content {
  padding: 20px 0;
}

.order-summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.order-label {
  font-size: 16px;
  color: #606266;
}

.order-value {
  font-size: 24px;
  font-weight: bold;
  color: #409EFF;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .action-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 768px) {
  .action-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .stats-cards .el-col {
    margin-bottom: 20px;
  }
}
</style>